package com.zretc.file.util;

import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/*
 * 文件上传工具类
 */
public class FileUploadUtils {

    public static final long FILE_MAX_SIZE = 1024 * 1024 * 100;

    // 随机生成文件名
    public static String extractFileName(MultipartFile file){
        // 获得原始文件名，为获取后缀
        String filename = file.getOriginalFilename();
        // 获得后缀名
        assert filename != null;
        String extension = filename.substring(filename.lastIndexOf("."));

        String randomName = UUID.randomUUID().toString().replace("-","");

        String name = randomName + extension;

        return name;
    }

    /*
    public static void main(String[] args) {
        String filename = "abacdase.jpg";

        String extension = filename.substring(filename.lastIndexOf("."));

        String randomName = UUID.randomUUID().toString().replace("-","");

        String name = randomName + extension;

        System.out.println(name);
    }

     */
}
